package org.extreme.schooltalk;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class EmailAdapter extends ArrayAdapter{
	Context ctx;
	String[] mList;
	int resId;
	ViewWrapper wrapper;
	
	public EmailAdapter(Context context, int resId, String[] list) {
		super(context, resId, list);
		this.ctx = context;
		this.mList = list;
		this.resId = resId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView==null){
			LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(resId, null);
			wrapper = new ViewWrapper(convertView);
			convertView.setTag(wrapper);
		}else
			wrapper = (ViewWrapper)convertView.getTag();
		
		wrapper.getLabel().setText(mList[position]);
		wrapper.getLabel().setTextColor(R.drawable.textColor);
		
		return convertView;
	}
	
	class ViewWrapper{
		
		View base;
		TextView label = null;
		
		ViewWrapper(View base){
			this.base = base;
		}
		TextView getLabel(){
			if(label == null){
				label = (TextView)base.findViewById(android.R.id.text1);
			}
			return label;
		}	
	}
}

